/*
 * WrapStrategy.cpp
 *
 *  Created on: 2010-01-13
 *      Author: adas
 */

#include "WrapStrategy.h"

bool WrapStrategy::runStrategy(Element & el_, int populationCount_, double weightFactor_, const std::vector<Element *> &population_,
				const std::vector<Bound> &bounds_, const Element &oldEl_)
{
	calculatePoint(el_, populationCount_, weightFactor_, population_);

	for(int i = 0; i < el_.getDimensionCount(); ++i)
	{
		double boundWidth = bounds_[i].getMax() - bounds_[i].getMin();
		if( el_.getValueAt(i) < bounds_[i].getMin() )
		{
			double temp = el_.getValueAt(i);
			do
			{
				temp += boundWidth;
			} while(temp < bounds_[i].getMin());

			el_.setValueAt(i, temp);
		}
		else if( el_.getValueAt(i) > bounds_[i].getMax() )
		{
			double temp = el_.getValueAt(i);
			do
			{
				temp -= boundWidth;
			} while(temp > bounds_[i].getMax());

			el_.setValueAt(i, temp);
		}
	}

	return true;
}
